package com.onlyxiahui.common.utils.base.lang.reflect;

/**
 * Date 2019-01-11 14:14:40<br>
 * Description
 *
 * @author XiaHui<br>
 * @since 1.0.0
 */
public class PropertyUtil {

	public static boolean isNull(Object o) {
		return (null == o);
	}

	public static boolean isNotNull(Object o) {
		return !isNull(o);
	}

	public static boolean isEmpty(Object o) {
		return (null == o || "".equals(o));
	}

	public static boolean isNotEmpty(Object o) {
		return !(isEmpty(o));
	}

	public static boolean isPrimitive(Class<?> o) {
		return (null != o && o.isPrimitive())
				|| (o == Integer.class)
				|| (o == Long.class)
				|| (o == Float.class)
				|| (o == Double.class)
				|| (o == Byte.class)
				|| (o == Character.class)
				|| (o == Boolean.class)
				|| (o == Short.class)
				|| (o == int.class)
				|| (o == long.class)
				|| (o == float.class)
				|| (o == double.class)
				|| (o == byte.class)
				|| (o == char.class)
				|| (o == short.class)
				|| (o == boolean.class);
	}

	public static boolean isInteger(Class<?> o) {
		return (o == Integer.class) || (o == int.class);
	}

	public static boolean isLong(Class<?> o) {
		return (o == Long.class) || (o == long.class);
	}

	public static boolean isFloat(Class<?> o) {
		return (o == Float.class) || (o == float.class);
	}

	public static boolean isDouble(Class<?> o) {
		return (o == Double.class) || (o == double.class);
	}

	public static boolean isByte(Class<?> o) {
		return (o == Byte.class) || (o == byte.class);
	}

	public static boolean isCharacter(Class<?> o) {
		return (o == Character.class) || (o == char.class);
	}

	public static boolean isBoolean(Class<?> o) {
		return (o == Boolean.class) || (o == boolean.class);
	}

	public static boolean isShort(Class<?> o) {
		return (o == Short.class) || (o == short.class);
	}

	/******************************/

	public static boolean isInteger(Object o) {
		return (o instanceof Integer);
	}

	public static boolean isLong(Object o) {
		return (o instanceof Long);
	}

	public static boolean isFloat(Object o) {
		return (o instanceof Float);
	}

	public static boolean isDouble(Object o) {
		return (o instanceof Double);
	}

	public static boolean isByte(Object o) {
		return (o instanceof Byte);
	}

	public static boolean isCharacter(Object o) {
		return (o instanceof Character);
	}

	public static boolean isBoolean(Object o) {
		return (o instanceof Boolean);
	}

	public static boolean isShort(Object o) {
		return (o instanceof Short);
	}

	/**
	 * 判断对象是否为8种基本类型的对象。
	 *
	 * @param o
	 * @return boolean
	 */
	public static boolean isPrimitive(Object o) {
		return (o instanceof Integer)
				|| (o instanceof Long)
				|| (o instanceof Float)
				|| (o instanceof Double)
				|| (o instanceof Byte)
				|| (o instanceof Character)
				|| (o instanceof Boolean)
				|| (o instanceof Short)
				|| (null != o && isPrimitive(o.getClass()));
	}

	/**
	 * Description 是否为字符串类型 <br>
	 * Date 2019-03-30 17:31:10<br>
	 *
	 * @param o
	 * @return boolean
	 * @since 1.0.0
	 */
	public static boolean isString(Object o) {
		return (o instanceof String);
	}

	/**
	 * Description 是否为字符串类型 <br>
	 * Date 2019-03-30 17:31:01<br>
	 *
	 * @param o
	 * @return boolean
	 * @since 1.0.0
	 */
	public static boolean isString(Class<?> o) {
		return (o == String.class);
	}

	@SuppressWarnings("unchecked")
	public static <T> T getDefaultValue(Class<T> clazz) {
		Object object = null;
		if (clazz == int.class || (clazz == Integer.class)) {
			object = 0;
		} else if (clazz == long.class || (clazz == Long.class)) {
			object = 0L;
		} else if (clazz == float.class || (clazz == Float.class)) {
			object = 0.0F;
		} else if (clazz == double.class || (clazz == Double.class)) {
			object = 0.00D;
		} else if (clazz == byte.class || (clazz == Byte.class)) {
			object = (byte) 0;
		} else if (clazz == char.class || (clazz == Character.class)) {
			object = '\u0000';
		} else if (clazz == short.class || (clazz == Short.class)) {
			object = 0;
		} else if (clazz == boolean.class || (clazz == Boolean.class)) {
			object = false;
		}
		return ((T) object);
	}

	/**
	 * Date 2019-03-30 17:17:16<br>
	 * Description int to long
	 *
	 * @param i
	 * @return long
	 * @since 1.0.0
	 */
	public static long intToLong(int i) {
		long l = i & 0x7fffffffL;
		if (i < 0) {
			l |= 0x080000000L;
		}
		return l;
	}
}
